package com.neegix.organization.dept.infrastructure.repository.impl;

import com.neegix.application.query.NebulaSQL;
import com.neegix.organization.dept.application.assembler.DeptAssembler;
import com.neegix.organization.dept.application.cqrs.query.DeptQueryRepository;
import com.neegix.organization.dept.application.cqrs.query.condition.DeptWhereGroup;
import com.neegix.organization.dept.application.dto.DeptDTO;
import com.neegix.organization.dept.infrastructure.repository.convert.DeptConverter;
import com.neegix.organization.dept.infrastructure.repository.dataobject.DeptDO;
import com.neegix.organization.dept.infrastructure.repository.mapper.DeptMapper;
import com.neegix.organization.dept.infrastructure.repository.mapper.customized.DeptCustomizedMapper;
import com.neegix.organization.dept.interfaces.vo.DeptVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

 /**
  * This file is auto-generated by nebula-framework-generator.
  * The auto-generation plugin was developed using IntelliJ IDEA Community Edition.
  * Thanks to JetBrains for their outstanding contributions to the developer community.
  * <p>
  * The code generated by this tool is owned by the user of the tool.
  * The tool itself is copyrighted by <a href="https://www.neegix.com">https://www.neegix.com</a>.
  *
  * @author <a href="https://www.neegix.com">https://www.neegix.com</a>
  * @version 1.0.0
  * @since 2024-12-10 14:48:03
  */

@Repository
public class DeptQueryRepositoryImpl implements DeptQueryRepository {

    @Autowired
    private DeptMapper deptMapper;

    @Autowired
    private DeptCustomizedMapper deptCustomizedMapper;

    @Override
    public Optional<DeptVO> findById(Long id) {
        DeptDO deptDO = deptMapper.selectByPrimaryKey(id);
        return Optional.ofNullable(DeptAssembler.INSTANCE.covertVO(DeptConverter.INSTANCE.covertDTO(deptDO)));
    }

    @Override
    public Integer selectCount(List<Long> ids) {
        return deptCustomizedMapper.selectCountByIds(ids);
    }

    @Override
    public List<DeptVO> findList(Long pkBizUnit, DeptDTO deptDTO) {
        NebulaSQL nebulaSQL = new NebulaSQL();
        nebulaSQL.createWhereGroups(DeptWhereGroup.class)
           .andAbbreviationLikeTo(deptDTO.getAbbreviation())
           .andCodeLikeTo(deptDTO.getCode())
           .andCreateTimeBetween(deptDTO.getStartCreateTime(),deptDTO.getEndCreateTime())
           .andCreateUserEqualTo(deptDTO.getCreateUser())
           .andDeletedEqualTo(deptDTO.getDeleted())
           .andEnabledEqualTo(deptDTO.getEnabled())
           .andIdEqualTo(deptDTO.getId())
           .andManagerLikeTo(deptDTO.getManager())
           .andMobilePhoneLikeTo(deptDTO.getMobilePhone())
           .andNameLikeTo(deptDTO.getName())
           .andPidEqualTo(deptDTO.getPid())
           .andPkBizUnitEqualTo(pkBizUnit)
           .andTelLikeTo(deptDTO.getTel())
           .andUpdateTimeBetween(deptDTO.getStartUpdateTime(),deptDTO.getEndUpdateTime())
           .andUpdateUserEqualTo(deptDTO.getUpdateUser());
           

        List<DeptDO> result = deptMapper.selectList(nebulaSQL);
        return DeptAssembler.INSTANCE.covertVO(DeptConverter.INSTANCE.covertDTOS(result));
    }
}
